package io.yunjiao.apijson.example;

import io.yunjiao.apijson.example.fastjson2.CustomFastjson2Creator;
import io.yunjiao.apijson.fastjson2.Fastjson2Creator;
import io.yunjiao.apijson.spring.boot.autoconfigure.ApijsonSqlProperties;
import io.yunjiao.apijson.spring.boot.autoconfigure.condition.ApllicationCondition;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 通用配置
 *
 * @author yangyunjiao
 */
@Slf4j
@Conditional(ApllicationCondition.OnFastjson2.class)
@Configuration
public class ExampleDataSourceAutoConfiguration {
    @PostConstruct
    public void postConstruct() {
        log.info("Example DataSource Auto Configuration");
    }

//    @Bean
//    public DataSource DriverManagerDataSource() {
//        log.debug("Configure Bean [Driver Manager DataSource]");
//        DriverManagerDataSource dataSource = new DriverManagerDataSource();
//        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
//        dataSource.setUrl("jdbc:mysql://localhost:3306/apijson_ut?userSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8"); // 内存模式
//        dataSource.setUsername("root");
//        dataSource.setPassword("root");
//        return dataSource;
//    }

    @Bean
    public Fastjson2Creator customFastjson2Creator(DataSource dataSource,
                                                   ApijsonSqlProperties sqlProperties) {
        log.debug("Configure Bean [Custom Fastjson2 Creator]");
        return new CustomFastjson2Creator(dataSource, sqlProperties);
    }


}
